package com.vito.dcs.intface;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.dcs.DcsConstants;

@Controller
@RequestMapping("/dcs/intface")
public class IntfaceAction extends BaseAction{

	private static final Logger log = LoggerFactory.getLogger(IntfaceAction.class);
	
	@Reference
	private IntfaceService intfaceService;
	
	/**
	 * 根据标段id查询所有桩号
	 * @param map
	 * @return
	 */
	@RequestMapping("queryPileKey")
	@ResponseBody
	public Result queryPileKey(@RequestParam Map<String,String> map){
		Result rs = new Result();
		try {
			rs.setCode(Result.CODE_OK);
			rs.setData(intfaceService.queryPileKey(map));
		} catch (Exception e) {
			log.debug("查询失败", e);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg("查询失败");
		}
		return rs;
	}
	
	/**
	 * 查询中心点坐标
	 * @param map
	 * @return
	 */
	@RequestMapping("findCenterCoor")
	@ResponseBody
	public Result findCenterCoor(@RequestParam Map<String,String> map){
		Result rs = new Result();
		try{
			rs.setCode(Result.CODE_OK);
			rs.setData(intfaceService.findCenterCoor(map));
		}catch (Exception e) {
			log.debug("查询失败", e);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg("查询失败");
		}
		return rs;
	}
	
	/**
	 * 根据工区id查询所有车辆
	 * @param map
	 * @return
	 */
	@RequestMapping("querySysConstructionVehicleByAreaId")
	@ResponseBody
	public Result querySysConstructionVehicleByAreaId(@RequestParam Map<String,String> map){
		Result rs = new Result();
		try{
			rs.setData(intfaceService.querySysConstructionVehicleByAreaId(map));
			rs.setCode(Result.CODE_OK);
		}catch(Exception ex){
			log.error("查询失败",ex);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg(ResMsg.EXECERR);
		}
		return rs;
	}
	
	@RequestMapping("findConTypeList")
	@ResponseBody
	public Result findConTypeList(){
		Result rs = new Result();
		try {
			rs.setCode(Result.CODE_OK);
			//Map<String,String> map = DcsConstants.CONSTRUC_TYPE;
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("TPJ", "摊铺机");
			map.put("JLYLJ", "胶轮压路机");
			map.put("GLYLJ", "钢轮压路机");
			rs.setData(map);
		} catch (Exception e) {
			log.debug("查询失败", e);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg("查询失败");
		}
		return rs;
	}
	
	/**
	 * 查询车辆轨迹
	 * @param map
	 * @return
	 */
	@RequestMapping("findSectionAndConstructionInfo")
	@ResponseBody
	public Result findSectionAndConstructionInfo(@RequestParam Map<String,String> map){
		Result rs = new Result();
		try{
			String conId = map.get("conId");
			if(null!=conId && !"".equals(conId)){
				rs = intfaceService.querySectionAndConstructionInfo(map);
			}else{
				rs = intfaceService.queryAllSectionAndConstructionInfo(map);
			}
		}catch (Exception e) {
			log.debug("查询失败", e);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg("查询失败");
		}
		return rs;
	}

	@RequestMapping("findLayerByTime")
	@ResponseBody
	public Result findLayerByTime(@RequestParam Map<String,String> map){
		Result rs = new Result();
		try{
			HashMap<String,String> layer = intfaceService.findLayerByTime(map);
			if(null!=layer){
				rs.setCode(Result.CODE_OK);
				rs.setData(layer);
			}else{
				rs.setCode(Result.CODE_NO_DATA);
				rs.setMsg("无匹配施工面层数据");
			}
		}catch (Exception e) {
			log.debug("查询失败", e);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg("查询失败");
		}
		return rs;
	}
	
	@RequestMapping("findConstructionInfoByConId")
	@ResponseBody
	public Result findConstructionInfoByConId(@RequestParam Map<String,String> map){
		Result rs = new Result();
		try{
			rs.setData(intfaceService.findConstructionInfoByConId(map));
			rs.setCode(Result.CODE_OK);
		}catch(Exception ex){
			log.error("查询失败",ex);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg(ResMsg.EXECERR);
		}
		return rs;
	}
	
}
